#include "copyright.h"
#include "system.h"
#include "network.h"
#include "post.h"
#include "interrupt.h"
#include "synch.h" 
#include "list.h" 

#include <iostream> 
#include <sstream> 
#include <string> 

#define maxNumOfLock 5000 
#define maxNumOfCV 5000 

 struct SynchStruct 
 { 
   char* name; 
   int clientID; 
   int owned; 
   int lockID;//used by conditions 
   int howManyAccessed;
   List *waitQueues; 
 }; 
  
 struct ClientStruct 
 { 
   int synchID; //= lock ID 
   int cvID; 
   int clientID; 
 }; 

SynchStruct *locks[maxNumOfLock]; 
int lockCounter = 0; 

Lock lockForLockArray ("lockForLockArray");	//Lock for Locks table
Lock lockForCVArray ("lockForCVArray");	//Lock for Conditions Table

  
SynchStruct *cvs[maxNumOfCV]; 
List *cvWaitQueues[maxNumOfCV]; 
int CVCounter = 0; 

int CreateLock(char* name); 
int Acquire(ClientStruct *cStruct); 
int Release(ClientStruct *cStruct); 
void DestroyLock(int index); 

int CreateCondition(char* name); 
int Wait(ClientStruct *cStruct); 
int Signal(ClientStruct *cStruct); 
int Broadcast(ClientStruct *cStruct); 
void DestroyCondition(int index); 

void server(int farAddr);
